<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<%@ page contentType="text/html; charset=utf-8" language="java"
	import="java.sql.*" errorPage=""%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>TracSetup</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="webmasterneo" />
<meta name="description"
	content="A short description of your site here." />
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" language="javascript1.5">
var param = 'inserisciTicket.do';
<c:if test="${param.modifica=='Y'}">
	param = 'modificaTicket.do';
</c:if>
	function doInsert(){
		
		document.forms[0].action=param;
		document.forms[0].submit();
	}
	function doAttach(page){
		var modifica = '';
		<c:if test="${param.modifica=='Y'}">
			modifica='modifica=Y';
			if(page.indexOf('?')==-1){
				modifica='?'+modifica;
			}else{
				modifica='&'+modifica;
			}
				
		</c:if>
		document.forms[0].action=page+modifica;
		document.forms[0].submit();
	}
</script>
</head>

<body>

<div id="header">
<div class="header"></div>
</div>

<div id="menu">
<div class="menu"><a href="esci.do">Esci</a></div>
<div class="menu"><a href="search.do">Elenco ticket</a></div>
<div class="menu"></div>
<div class="menu"></div>
<div class="menu"></div>
</div>

<div id="body">
<div class="spacer"></div>
<div class="content"><form:form acceptCharset="UTF-8"
	action="${action}" commandName="ticket" id="formTicket"
	enctype="multipart/form-data">
	<c:if test="${fn:length(ticket.listaProgetti)==1 }">
		<input type="hidden" name="idProgetto" id="idProgetto"
			value="<c:out value='${ticket.idProgetto}'/>" />
	</c:if>
	<input type="hidden" name="idOwner" id="idOwner"
		value="<c:out value='${ticket.idOwner}'/>" />
	<input type="hidden" name="idUtente" id="idUtente"
		value="<c:out value='${ticket.idUtente}'/>" />
	<input type="hidden" name="idTicket" id="idTicket"
		value="<c:out value='${ticket.idTicket}'/>" />
	<input type="hidden" name="modifica" id="modifica"
		value="<c:out value='${param.modifica}'/>" />

	<c:if test="${ param.idStorico!=null }">
		<input type="hidden" name="idStorico" id="idStorico"
			value="<c:out value='${param.idStorico}'/>" />
	</c:if>
	<table width="600" border="1" align="center">
		<tr>
			<td>Progetto</td>
			<td>
			<c:choose>
				<c:when test="${fn:length(ticket.listaProgetti)==1 }">
					<c:out value="${ticket.descrizioneProgetto }"></c:out>
				</c:when>
				<c:otherwise>
				<select name="idProgetto" id="idProgetto">
					<option value="-1">-- Seleziona progetto --</option>
					<c:forEach items="${ticket.listaProgetti}" var="item">
						<option value="<c:out value="${item.idProgetto}"/>"
							<c:if test="${item.idProgetto==param.idProgetto}">selected="selected"</c:if>><c:out
							value="${item.descrizione}" /></option>
					</c:forEach>
				</select>
				</c:otherwise>
			</c:choose>
			<form:errors path="idProgetto"></form:errors>
			</td>
		</tr>
		<tr>
			<td width="192">Titolo</td>
			<td width="392"><c:if
				test="${(ticket.idTicket==null || ticket.idTicket=='') && loginForm.utenti.profilo.descrizione!='DEVELOPER' }">
				<form:input path="titoloTicket" />
				<form:errors path="titoloTicket" />
			</c:if> <c:if
				test="${(ticket.idTicket!=null && ticket.idTicket!='') && loginForm.utenti.profilo.descrizione=='USER' }">
				<input type="hidden" name="titoloTicket"
					value="<c:out value='${ticket.titoloTicket}'/>" />
				<c:out value="${ticket.titoloTicket}" />
			</c:if> <c:if
				test="${(ticket.idTicket!=null  && ticket.idTicket!='') && loginForm.utenti.profilo.descrizione=='DEVELOPER' }">
				<input type="hidden" name="titoloTicket"
					value="<c:out value='${ticket.titoloTicket}'/>" />
				<c:out value="${ticket.titoloTicket}" />
			</c:if></td>
		</tr>
		<tr>
			<td>Descrizione</td>
			<td><c:if
				test="${loginForm.utenti.profilo.descrizione!='DEVELOPER' }">
				<form:textarea path="descrizione" cols="50" id="descrizione"
					rows="10" />
				<form:errors path="descrizione" />
			</c:if> <c:if test="${loginForm.utenti.profilo.descrizione=='DEVELOPER' }">
				<c:out value="${ticket.descrizione}" />
				<input type="hidden" name="descrizione" id="descrizione"
					value="<c:out value="${ticket.descrizione}"/>" />
			</c:if></td>
		</tr>
		<c:choose>
			<c:when test="${loginForm.utenti.profilo.descrizione=='DEVELOPER'}">
				<tr>
					<td>Stato</td>
					<td><select name="idStato" id="idStato">
						<c:forEach items="${stati}" var="item">
							<option value="<c:out value="${item.stati.idStato}"/>"
								<c:if test="${item.stati.idStato==idStato}">selected="selected"</c:if>><c:out
								value="${item.stati.descrizione}" /></option>
						</c:forEach>
					</select> <!--form:input path="statoTicket" id="statoTicket"  /--> <!--form:errors path="statoTicket"/-->
					</td>
				</tr>
			</c:when>
			<c:otherwise>
				<input type="hidden" value="<c:out value="${idStato}"/>"
					name="idStato" />
			</c:otherwise>
		</c:choose>
		<!-- tr>
			<td>Nome file</td>
			<td><form:input path="nomeFile" id="nomeFile" /></td>
		</tr-->
		<tr>
			<td>Allega file</td>
			<td><input type="file" name="file" id="allegato" /> <input
				type="submit" name="addAllegato" id="addAllegato" value="Allega"
				onclick="javascript:doAttach('addAllegato.do')" /> <form:errors path="file"></form:errors></td>
		</tr>
		<c:if test="${not empty allegati}">
			<tr>
				<td>Lista allegati</td>
				<td>
				<table>
					<c:forEach items="${allegati}" var="item">
						<tr>
							<td><a
								href="visualizzaAllegato.do?id=<c:out value="${item.idAllegato}" />"><c:out
								value="${item.nome}" /></a></td>
							<td><input type="submit" name="delAllegato" id="delAllegato"
								value="Rimuovi"
								onclick="javascript:doAttach('rimuoviAllegato.do?idAllegato=<c:out value="${item.idAllegato }"/>');" /></td>
						</tr>
					</c:forEach>
				</table>
				</td>
			</tr>
		</c:if>
		<c:if test="${loginForm.utenti.profilo.descrizione=='DEVELOPER'}">
			<tr>
				<td>Assegnato a</td>
				<td><c:choose>
					<c:when test="${owner==null}">
						<form:select path="idUtenteAssegnato"  >
							<option value="-1">--seleziona--</option>
							<form:options items="${assegnatari }" itemLabel="utenti.cognome" itemValue="utenti.idUtente"/>
							
						</form:select>
						<form:errors path="idUtenteAssegnato" />
					</c:when>
					<c:otherwise>
						<input type="hidden" value="<c:out value="${owner.idUtente}"/>" />
						<c:out value="${owner.cognome}" />
						<c:out value="${owner.nome}" />
					</c:otherwise>
				</c:choose></td>
			</tr>
		</c:if>
		<c:if test="${loginForm.utenti.profilo.descrizione=='DEVELOPER'}">

			<tr>
				<td>Prossima azione</td>
				<td><form:textarea path="prossimaAzione" cols="50"
					id="prossimaAzione" rows="5" /> <form:errors path="prossimaAzione" />
				</td>
			</tr>
			<tr>
				<td>Ore previste</td>
				<td><form:input path="orePreviste" id="orePreviste" /> <form:errors
					path="orePreviste" /></td>
			</tr>
			<!-- tr>
				<td>Giorni previsti</td>
				<td><form:input path="giorniPrevisti" id="giorniPrevisti" /> <form:errors
					path="giorniPrevisti" /></td>
			</tr-->
			<tr>
				<td>Ore consuntivate</td>
				<td><form:input path="oreConsuntivate" id="oreConsuntivate" />
				<form:errors path="oreConsuntivate" /></td>
			</tr>
			<!-- tr>
				<td>Giorni consuntivati</td>
				<td><form:input path="giorniConsuntivati"
					id="giorniConsuntivati" /> <form:errors path="giorniConsuntivati" />
				</td>
			</tr-->
		</c:if>

		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
		</tr>

		<tr>
			<td colspan="2"><input type="submit" name="inserisci"
				id="button" onclick="javascript:doInsert();" value="Invia" />
				<input type="button" name="Annulla"
				id="Annulla" value="Annulla" onclick="javascript:{window.location.href='search.do'}"/></td>
		</tr>
	</table>
</form:form>
</p>
</div>
<div class="spacer"></div>
<div id="footer">
<div class="footer"></div>
&copy; Copyright 2010 Setup s.r.l. All Rights Reserved.</div>
</div>

</body>

</html>
